<script setup>
import HomePanel from './HomePanel.vue'
import { getHotGoodsAPI } from '@/apis/home'
import { ref } from 'vue'
import { imageBaseURL } from '@/utils/request'

const hotGoodsList = ref([])
const getHotGoods = async () => {
  const res = await getHotGoodsAPI()
  hotGoodsList.value = res.result
}
getHotGoods()
</script>

<template>
  <HomePanel title="人气推荐" sub-title="人气爆款 不容错过">
    <template #main>
      <ul class="goods-list">
        <li v-for="item in hotGoodsList" :key="item.id">
          <RouterLink :to="`/detail/${item.id}`">
            <img v-img-lazy="imageBaseURL + item.picture" alt="" />
            <p class="name">{{ item.name }}</p>
            <p class="desc">{{ item.description }}</p>
            <p class="price">&yen;{{ item.price }}</p>
          </RouterLink>
        </li>
      </ul>
    </template>
  </HomePanel>
</template>

<style scoped lang="scss">
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;

  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    transition: all 0.5s;
    // padding: 0 12px;
    margin: 10px;
    position: relative;
    overflow: hidden;
    

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }

    img {
      width: 306px;
      height: 306px;
    }

    &::after {
      content: '特卖';
      position: absolute;
      top: 0;
      right: 0;
      width: 80px;
      height: 24px;
      background: #f56c6c;
      color: white;
      text-align: center;
      line-height: 24px;
      transform: rotate(45deg) translateX(29.29%) translateY(-29.29%);
      font-size: 12px;
    }

    .name {
      font-size: 16px;
      font-weight: 500;
      margin-top: 10px;
      margin-left: 12px;
      text-align: left;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .desc {
      font-size: 14px;
      color: #999;
      margin-left: 12px;
      margin-top: 6px;
      text-align: left;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .price {
      color: $priceColor;
      font-size: 22px;
      font-weight: bold;
      margin-left: 12px;
      margin-top: 10px;
      position: relative;
      padding-left: 50px;
      z-index: 1;

      &::before {
        content: '特卖价';
        position: absolute;
        left: 0;
        top: 50%;
        transform: translateY(-50%);
        display: inline-block;
        width: 45px;
        height: 18px;
        background-image: repeating-linear-gradient(90deg, #dc459f 0, #cc75d8 100%);
        color: #ffffff;
        font: 12px/18px "微软雅黑";
        text-align: center;
        border-radius: 9px;
        z-index: -1;
      }
      
      
      
      
    }
  }
}
</style>
